//
//  MemoryTopic.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/7/28.
//

import UIKit

class MemoryTopic {
    

    /// 题目
    var topic: String?
    /// 答案
    var answer: String?
    /// 输入的答案
    var inputAnswer: String?
    
    func answerIsCorrect() -> Bool {
        return answer == inputAnswer
    }
    
    func getResultDesc() -> NSMutableAttributedString {
        var sym = "√"
        var color = UIColor.black
        if !answerIsCorrect() {
            sym = "×"
            color = .red
        }
        let str = "\(topic ?? "") = \(answer ?? "") (\(inputAnswer ?? "空")) \(sym)"
        
        let attri = NSMutableAttributedString(string: str)
        let tmpRange = NSRange(location: str.count - 1, length: 1)
        
        attri.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: tmpRange)
        return attri
    }
}
